package com.jiuyou.clientController.attachedRecord;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.constant.DicConstants;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.attachedRecord.domain.AttachedRecord;
import com.ruoyi.attachedRecord.service.IAttachedRecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 检测记录Controller
 *
 * @author ruoyi
 * @date 2025-05-19
 */
@RestController
@RequestMapping("/client/attachedRecord")
public class ClientAttachedRecordController extends BaseController
{
    @Autowired
    private IAttachedRecordService attachedRecordService;


    /**
     * 查询检测记录列表
     */
    @GetMapping("/list")
    public List<AttachedRecord> list(AttachedRecord attachedRecord)
    {
        return attachedRecordService.selectAttachedRecordList(attachedRecord);
    }

    /**
     * 导出检测记录列表
     */
    @Log(title = "检测记录", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(AttachedRecord attachedRecord)
    {
        List<AttachedRecord> list = attachedRecordService.selectAttachedRecordList(attachedRecord);
        ExcelUtil<AttachedRecord> util = new ExcelUtil<AttachedRecord>(AttachedRecord.class);
        return util.exportExcel(list, "检测记录数据");
    }

    /**
     * 获取检测记录详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(attachedRecordService.selectAttachedRecordById(id));
    }

    /**
     * 新增检测记录
     */
    @Log(title = "检测记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AttachedRecord attachedRecord)
    {
        return toAjax(attachedRecordService.insertAttachedRecord(attachedRecord));
    }

    /**
     * 修改检测记录
     */
    @Log(title = "检测记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AttachedRecord attachedRecord)
    {
        attachedRecord.setUpdateType(DicConstants.BUSINESS_Manager.getCode());
        return toAjax(attachedRecordService.updateAttachedRecord(attachedRecord));
    }

    /**
     * 删除检测记录
     */
    @Log(title = "检测记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(attachedRecordService.logicDeleteAttachedRecord(ids,DicConstants.BUSINESS_Manager.getCode(),SecurityUtils.getUserId()));
    }
}
